$(function(){
    function ban(){
        $(".button1").attr("disabled",false)
        $(".button2").attr("disabled",false)
        if($(".page>option:selected").val()==1){
            // 禁用button1
            $(".button1").attr("disabled",true)
        }else if($(".page>option:selected").val()==15){
            // 禁用button2
            $(".button2").attr("disabled",true)
        }
    }

    $(".button2").click(function(){
        $(".page>option:selected").next().prop("selected","selected").siblings().removeAttr("selected")
        ban();
        drivepage($(".page>option:selected").val())
    })
    $(".button1").click(function(){
        $(".page>option:selected").prev().prop("selected","selected").siblings().removeAttr("selected")
        ban();
        drivepage($(".page>option:selected").val())
    })
    $(".page").change(function(){
        ban();
        drivepage($(".page>option:selected").val())
    })
    function drivepage(pageid){
        pageid--;
        let html="";
        $.ajax({
            url: "http://chst.vip:1234/api/getmoneyctrl",
            type: "get",
            data: {pageid:pageid},
            success(res) {
                let { result } = res;
                console.log(result);
                result.forEach((item, index, array) => {
                    html += `
                    <li>
                        <a href="discount.html?productid=${item.productId}">
                            <div class="left fl">
                                ${item.productImg2}
                            </div>
                            <div class="right">
                                <div class="title">
                                    <h4>
                                        ${item.productName}
                                    </h4>
                                </div>
                                <div class="other">
                                    <span class="mall">
                                        ${item.productFrom}丨${item.productTime}
                                    </span>
                                    <span class="fr">
                                        <span class="iconfont">&#xe638;</span>${item.productComCount}
                                    </span>
                                </div>
                            </div>
                        </a>
                    </li>
                    `
                })
                $('.discount>ul').html(html)
            },
            error(err) {
                console.log(err);
            }
        })
    }
    drivepage(1);
})